﻿namespace NTLib.Pipe.Streaming.Formats
{
    using Core.Exceptions;
    using Core.Extensions;
    using Core.Resources;
    using Core.Threading;
    using NTLib.Core.Factories;

    /// <summary>
    /// Managed the instance of all the formater.
    /// Only one instance at the time could be instanciated
    /// </summary>
    public class PackageFormatManager : ComponentFactory<IPackageFormater>
    {
        #region Fields

        private static PackageFormatManager s_instance;

        #endregion

        #region Ctor

        /// <summary>
        /// Prevents a default instance of the <see cref="PackageFormatManager"/> class from being created.
        /// </summary>
        public PackageFormatManager()
        {
            if (s_instance != null)
            {
                throw new SingletonException(StandardErrorMessages
                                             .OnlyOneInstanceAtTheTime
                                             .Argument(typeof(PackageFormatManager)));
            }
            s_instance = this;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the instance.
        /// </summary>
        public static PackageFormatManager Instance
        {
            get { return s_instance; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Resets the singleton instance.
        /// </summary>
        [NotThreadSafe]
        protected void ResetSingletonInstance()
        {
            s_instance = null;
        }

        #endregion
    }
}
